package com.bjdd.jdy.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bjdd.jdy.R;
import com.bjdd.jdy.entity.BankCardBean;
import com.bjdd.jdy.util.L;
import com.yanzhenjie.recyclerview.swipe.SwipeMenuAdapter;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/5/10.
 */

public class BankCardAdapter extends SwipeMenuAdapter<BankCardAdapter.ViewHolder> {


    private Context mContext;
    private List<BankCardBean> data;

    public BankCardAdapter(Context context, List<BankCardBean> list) {
        this.mContext = context;
        this.data = list;
    }

    @Override
    public View onCreateContentView(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_bank_card, parent, false);
        return view;
    }

    @Override
    public ViewHolder onCompatCreateViewHolder(View realContentView, int viewType) {
        ViewHolder viewHolder;
        viewHolder = new ViewHolder(realContentView);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        BankCardBean card = data.get(position);
        L.d("银行名称："+card.getBank().getBankName());
        holder.tvBankCardName.setText(card.getBank().getBankName());
        String cardNo = "**** **** **** ";
        String c = card.getBankcard().substring(card.getBankcard().length() - 4);
        cardNo += c;
        holder.tvBankCardNo.setText(cardNo);
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.tv_bank_card_name)
        TextView tvBankCardName;
        @Bind(R.id.tv_bank_card_type)
        TextView tvBankCardType;
        @Bind(R.id.tv_bank_card_no)
        TextView tvBankCardNo;
        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
